package main

import (
	"context"
	"github.com/vearch/vearch/proto/pspb"
	"google.golang.org/grpc"
	"log"
)

/**
this case is use grpc to search by router
*/
func main() {
	//conn, err := grpc.Dial("11.16.107.155:9002", grpc.WithInsecure())
	conn, err := grpc.Dial("11.19.94.69:9002", grpc.WithInsecure())

	if err != nil {
		log.Fatalf("did not connect: %v", err)
	}

	defer func() {
		if err := conn.Close(); err != nil {
			panic(err)
		}
	}()

	api := pspb.NewRpcApiClient(conn)

	//test no query
	response, err := api.Search(context.Background(), &pspb.RpcSearchRequest{
		Head: &pspb.RpcRequestHead{TimeOutMs: 10000},
		//DbName:    "test_vector_db",
		//SpaceName: "vector_space",
		DbName:    "ts_db",
		SpaceName: "ts_space",
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Println(response)

	//test with query
	response, err = api.Search(context.Background(), &pspb.RpcSearchRequest{
		Head: &pspb.RpcRequestHead{TimeOutMs: 10000},
		//DbName:    "test_vector_db",
		//SpaceName: "vector_space",
		DbName:    "ts_db",
		SpaceName: "ts_space",
		Query: `
			{
				"query": {
					"filter": [],
					"sum": [{
						"field": "feature",
						"feature": [0.0, 0.065971, 0.0, 0.081162, 0.006925, 0.073766, 0.0, 0.013249, 0.0, 0.039984, 0.0, 0.0, 0.016911, 0.0, 0.006823, 0.012092, 0.0, 0.0, 0.017629, 0.003926, 0.001651, 0.021931, 0.023925, 0.00849, 0.02472, 0.008486, 0.104382, 0.005867, 0.002013, 0.024599, 0.008619, 0.0, 0.020307, 0.0, 0.05296, 0.02283, 0.0, 0.043208, 0.004723, 0.011599, 0.012899, 0.001433, 0.007914, 0.060652, 0.044208, 0.018909, 0.076264, 0.0, 0.019626, 0.018949, 0.02064, 0.045818, 0.069649, 0.029722, 0.026741, 0.01154, 0.004454, 0.054783, 0.025979, 0.100258, 0.0, 0.0, 0.012625, 0.034267, 0.0, 0.0, 0.07787, 0.039896, 0.0, 0.0, 0.0, 0.04836, 0.02437, 0.026807, 0.0, 0.084023, 0.001334, 0.101979, 0.0, 0.120906, 0.0, 0.030269, 0.026205, 0.0, 0.0, 0.051473, 0.121412, 0.072993, 0.041443, 0.007414, 0.016106, 0.0, 0.045215, 0.021443, 0.016213, 0.131052, 0.057983, 0.0, 0.065004, 0.036487, 0.0, 0.06293, 0.026097, 0.033678, 0.002489, 0.0, 0.067409, 0.022819, 0.013598, 0.0, 0.023166, 0.0, 0.0, 0.00518, 0.013208, 0.0, 0.003762, 0.034987, 0.0, 0.037859, 0.0, 0.0, 0.0, 0.023172, 0.086252, 0.023661, 0.007707, 0.003928, 0.007365, 0.334064, 0.018054, 0.0, 0.04198, 0.0, 0.017349, 0.0, 0.031722, 0.001031, 0.086498, 0.0, 0.122531, 0.0, 0.093435, 0.0, 0.009355, 0.0, 0.009479, 0.03897, 0.031999, 0.027841, 0.023937, 0.0, 0.012016, 0.0, 0.0, 0.022808, 0.0, 0.009286, 0.0, 0.006031, 0.0, 0.072617, 0.03921, 0.042278, 0.00806, 0.020886, 0.026893, 0.0, 0.0, 0.0, 0.0, 0.147373, 0.0, 0.0, 0.009821, 0.020363, 0.085547, 0.194719, 0.001523, 0.022988, 0.055334, 0.0, 0.0, 0.031008, 0.03128, 0.0, 0.004311, 0.089122, 0.021472, 0.0, 0.0, 0.01043, 0.125264, 0.0, 0.007385, 0.0, 0.0, 0.026403, 0.0, 0.0, 0.021199, 0.041743, 0.0, 0.013996, 0.046098, 0.0, 0.056733, 0.0, 0.0, 0.022062, 0.063459, 0.004465, 0.0, 0.186984, 0.004112, 0.021499, 0.026635, 0.041718, 0.0, 0.0, 0.0, 0.034111, 0.023776, 0.018346, 0.0, 0.033419, 0.0, 0.029784, 0.019915, 0.065961, 0.106869, 0.003077, 0.065471, 0.095643, 0.0, 0.013596, 0.009592, 0.048217, 0.042995, 0.019694, 0.012632, 0.014646, 0.007979, 0.004707, 0.092743, 0.0, 0.012279, 0.0, 0.036042, 0.019771, 0.059895, 0.0, 0.047421, 0.0, 0.0, 0.01578, 0.036085, 0.002681, 0.0, 0.05295, 0.00212, 0.008939, 0.089044, 0.0, 0.003987, 0.008245, 0.011103, 0.064644, 0.0, 0.011015, 0.0, 0.0, 0.09049, 0.00953, 0.0, 0.01127, 0.122458, 0.037518, 0.000752, 0.034012, 0.038665, 0.0, 0.048054, 0.0, 0.0, 0.010426, 0.0, 0.0, 0.0, 0.0, 0.033385, 0.018034, 0.014413, 0.0, 0.049741, 0.0381, 0.027641, 0.0, 0.041459, 0.0, 0.015517, 0.0, 0.114774, 0.005725, 0.117292, 0.028356, 0.013191, 0.003428, 0.0, 0.009672, 0.0, 0.0, 0.037291, 0.0, 0.046888, 0.002796, 0.098801, 0.016964, 0.0, 0.069957, 0.110383, 0.039199, 0.015382, 0.02599, 0.026209, 0.0, 0.046598, 0.00177, 0.044823, 0.0, 0.006756, 0.05804, 0.004234, 0.034252, 0.024823, 0.042017, 0.030202, 0.007849, 0.002583, 0.000806, 0.159674, 0.0, 0.068341, 0.0, 0.022589, 0.0, 0.066626, 0.000576, 0.0, 0.001955, 0.055975, 0.001544, 0.045472, 0.049019, 0.006195, 0.033586, 0.044293, 0.020779, 0.043994, 0.119287, 0.0, 0.028594, 0.0, 0.0, 0.0, 0.020003, 0.02533, 0.030106, 0.103045, 0.06668, 0.0, 0.013858, 0.0, 0.0, 0.021907, 0.002506, 0.008379, 0.0, 0.040824, 0.011151, 0.0, 0.177697, 0.012873, 0.0, 0.049822, 0.024142, 0.0, 0.045847, 0.0, 0.0, 0.0, 0.125148, 0.0, 0.0, 0.018441, 0.005471, 0.025486, 0.002482, 0.046999, 0.01108, 0.033831, 0.014154, 0.0, 0.0, 0.013594, 0.00603, 0.003375, 0.039545, 0.010907, 0.0, 0.0, 0.0, 0.00288, 0.0, 0.0, 0.04072, 0.064472, 0.036312, 0.010808, 0.030552, 0.022376, 0.0, 0.014053, 0.114169, 0.002342, 0.020458, 0.0, 0.001452, 0.030332, 0.056871, 0.009424, 0.054278, 0.000969, 0.0, 0.009568, 0.028523, 0.00521, 0.0, 0.058871, 0.031259, 0.030749, 0.02288, 0.093115, 0.051406, 0.089677, 0.0, 0.0, 0.015494, 0.053959, 0.025442, 0.028148, 0.030278, 0.0, 0.005872, 0.002804, 0.018462, 0.076094, 0.0, 0.017587, 0.02332, 0.010412, 0.028708, 0.0, 0.031188, 0.0, 0.023535, 0.033284, 0.070313, 0.03711, 0.036305, 0.064223, 0.006191, 0.016537, 0.008415, 0.011728, 0.057372, 0.0, 0.009312, 0.011161, 0.127967, 0.021028, 0.032517, 0.0, 0.014864, 0.0, 0.0, 0.061219, 0.009899, 0.0, 0.15048, 0.0, 0.0, 0.036781, 0.0, 0.111955, 0.021214, 0.023795, 0.014142, 0.118345, 0.071317, 0.024041, 0.0, 0.0, 0.002982, 0.008808, 0.0, 0.0, 0.01605, 0.016581, 0.005676, 0.008882, 0.0, 0.134603, 0.036104, 0.033216, 0.028037, 0.024447, 0.055866, 0.054837, 0.068341, 0.0, 0.047462, 0.024916, 0.029574, 0.050058, 0.0, 0.1086, 0.020111, 0.0, 0.00103, 0.043128, 0.053088, 0.0, 0.032511, 0.069275, 0.0, 0.016703, 0.016437, 0.015997, 0.060473, 0.021266, 0.005723, 0.138001, 0.071008, 0.021814, 0.033982, 0.009205, 0.108593, 0.015237, 0.074121, 0.013281, 0.000191, 0.029631, 0.0519, 0.061154, 0.086131, 0.0, 0.049096, 0.082816, 0.072189, 0.052865, 0.0, 0.015066, 0.041518, 0.069102, 0.045476, 0.021399, 0.011514, 0.003963, 0.034423, 0.0, 0.04961, 0.096743, 0.04341, 0.020693, 0.0, 0.0, 0.001971, 0.048771, 0.048558, 0.0, 0.017236, 0.0, 0.04677, 0.0467, 0.03194, 0.0, 0.048829, 0.026097, 0.042147, 0.0, 0.005696, 0.0, 0.049209, 0.063318, 0.011795, 0.036663, 0.0, 0.11124, 0.002566, 0.009413, 0.0, 0.0, 0.0, 0.092952, 0.0, 0.043978, 0.192276, 0.104189, 0.054416, 0.106153, 0.009525, 0.0, 0.012452, 0.004012, 0.061031, 0.0, 0.0, 0.012454, 0.0621, 0.059129, 0.004631, 0.021704, 0.0, 0.016536, 0.05911, 0.041772, 0.030186, 0.029198, 0.0, 0.0, 0.057916, 0.029196, 0.005615, 0.0, 0.005348, 0.058839, 0.044673, 0.000128, 0.0, 0.0, 0.065971, 0.0, 0.081162, 0.006925, 0.073766, 0.0, 0.013249, 0.0, 0.039984, 0.0, 0.0, 0.016911, 0.0, 0.006823, 0.012092, 0.0, 0.0, 0.017629, 0.003926, 0.001651, 0.021931, 0.023925, 0.00849, 0.02472, 0.008486, 0.104382, 0.005867, 0.002013, 0.024599, 0.008619, 0.0, 0.020307, 0.0, 0.05296, 0.02283, 0.0, 0.043208, 0.004723, 0.011599, 0.012899, 0.001433, 0.007914, 0.060652, 0.044208, 0.018909, 0.076264, 0.0, 0.019626, 0.018949, 0.02064, 0.045818, 0.069649, 0.029722, 0.026741, 0.01154, 0.004454, 0.054783, 0.025979, 0.100258, 0.0, 0.0, 0.012625, 0.034267, 0.0, 0.0, 0.07787, 0.039896, 0.0, 0.0, 0.0, 0.04836, 0.02437, 0.026807, 0.0, 0.084023, 0.001334, 0.101979, 0.0, 0.120906, 0.0, 0.030269, 0.026205, 0.0, 0.0, 0.051473, 0.121412, 0.072993, 0.041443, 0.007414, 0.016106, 0.0, 0.045215, 0.021443, 0.016213, 0.131052, 0.057983, 0.0, 0.065004, 0.036487, 0.0, 0.06293, 0.026097, 0.033678, 0.002489, 0.0, 0.067409, 0.022819, 0.013598, 0.0, 0.023166, 0.0, 0.0, 0.00518, 0.013208, 0.0, 0.003762, 0.034987, 0.0, 0.037859, 0.0, 0.0, 0.0, 0.023172, 0.086252, 0.023661, 0.007707, 0.003928, 0.007365, 0.334064, 0.018054, 0.0, 0.04198, 0.0, 0.017349, 0.0, 0.031722, 0.001031, 0.086498, 0.0, 0.122531, 0.0, 0.093435, 0.0, 0.009355, 0.0, 0.009479, 0.03897, 0.031999, 0.027841, 0.023937, 0.0, 0.012016, 0.0, 0.0, 0.022808, 0.0, 0.009286, 0.0, 0.006031, 0.0, 0.072617, 0.03921, 0.042278, 0.00806, 0.020886, 0.026893, 0.0, 0.0, 0.0, 0.0, 0.147373, 0.0, 0.0, 0.009821, 0.020363, 0.085547, 0.194719, 0.001523, 0.022988, 0.055334, 0.0, 0.0, 0.031008, 0.03128, 0.0, 0.004311, 0.089122, 0.021472, 0.0, 0.0, 0.01043, 0.125264, 0.0, 0.007385, 0.0, 0.0, 0.026403, 0.0, 0.0, 0.021199, 0.041743, 0.0, 0.013996, 0.046098, 0.0, 0.056733, 0.0, 0.0, 0.022062, 0.063459, 0.004465, 0.0, 0.186984, 0.004112, 0.021499, 0.026635, 0.041718, 0.0, 0.0, 0.0, 0.034111, 0.023776, 0.018346, 0.0, 0.033419, 0.0, 0.029784, 0.019915, 0.065961, 0.106869, 0.003077, 0.065471, 0.095643, 0.0, 0.013596, 0.009592, 0.048217, 0.042995, 0.019694, 0.012632, 0.014646, 0.007979, 0.004707, 0.092743, 0.0, 0.012279, 0.0, 0.036042, 0.019771, 0.059895, 0.0, 0.047421, 0.0, 0.0, 0.01578, 0.036085, 0.002681, 0.0, 0.05295, 0.00212, 0.008939, 0.089044, 0.0, 0.003987, 0.008245, 0.011103, 0.064644, 0.0, 0.011015, 0.0, 0.0, 0.09049, 0.00953, 0.0, 0.01127, 0.122458, 0.037518, 0.000752, 0.034012, 0.038665, 0.0, 0.048054, 0.0, 0.0, 0.010426, 0.0, 0.0, 0.0, 0.0, 0.033385, 0.018034, 0.014413, 0.0, 0.049741, 0.0381, 0.027641, 0.0, 0.041459, 0.0, 0.015517, 0.0, 0.114774, 0.005725, 0.117292, 0.028356, 0.013191, 0.003428, 0.0, 0.009672, 0.0, 0.0, 0.037291, 0.0, 0.046888, 0.002796, 0.098801, 0.016964, 0.0, 0.069957, 0.110383, 0.039199, 0.015382, 0.02599, 0.026209, 0.0, 0.046598, 0.00177, 0.044823, 0.0, 0.006756, 0.05804, 0.004234, 0.034252, 0.024823, 0.042017, 0.030202, 0.007849, 0.002583, 0.000806, 0.159674, 0.0, 0.068341, 0.0, 0.022589, 0.0, 0.066626, 0.000576, 0.0, 0.001955, 0.055975, 0.001544, 0.045472, 0.049019, 0.006195, 0.033586, 0.044293, 0.020779, 0.043994, 0.119287, 0.0, 0.028594, 0.0, 0.0, 0.0, 0.020003, 0.02533, 0.030106, 0.103045, 0.06668, 0.0, 0.013858, 0.0, 0.0, 0.021907, 0.002506, 0.008379, 0.0, 0.040824, 0.011151, 0.0, 0.177697, 0.012873, 0.0, 0.049822, 0.024142, 0.0, 0.045847, 0.0, 0.0, 0.0, 0.125148, 0.0, 0.0, 0.018441, 0.005471, 0.025486, 0.002482, 0.046999, 0.01108, 0.033831, 0.014154, 0.0, 0.0, 0.013594, 0.00603, 0.003375, 0.039545, 0.010907, 0.0, 0.0, 0.0, 0.00288, 0.0, 0.0, 0.04072, 0.064472, 0.036312, 0.010808, 0.030552, 0.022376, 0.0, 0.014053, 0.114169, 0.002342, 0.020458, 0.0, 0.001452, 0.030332, 0.056871, 0.009424, 0.054278, 0.000969, 0.0, 0.009568, 0.028523, 0.00521, 0.0, 0.058871, 0.031259, 0.030749, 0.02288, 0.093115, 0.051406, 0.089677, 0.0, 0.0, 0.015494, 0.053959, 0.025442, 0.028148, 0.030278, 0.0, 0.005872, 0.002804, 0.018462, 0.076094, 0.0, 0.017587, 0.02332, 0.010412, 0.028708, 0.0, 0.031188, 0.0, 0.023535, 0.033284, 0.070313, 0.03711, 0.036305, 0.064223, 0.006191, 0.016537, 0.008415, 0.011728, 0.057372, 0.0, 0.009312, 0.011161, 0.127967, 0.021028, 0.032517, 0.0, 0.014864, 0.0, 0.0, 0.061219, 0.009899, 0.0, 0.15048, 0.0, 0.0, 0.036781, 0.0, 0.111955, 0.021214, 0.023795, 0.014142, 0.118345, 0.071317, 0.024041, 0.0, 0.0, 0.002982, 0.008808, 0.0, 0.0, 0.01605, 0.016581, 0.005676, 0.008882, 0.0, 0.134603, 0.036104, 0.033216, 0.028037, 0.024447, 0.055866, 0.054837, 0.068341, 0.0, 0.047462, 0.024916, 0.029574, 0.050058, 0.0, 0.1086, 0.020111, 0.0, 0.00103, 0.043128, 0.053088, 0.0, 0.032511, 0.069275, 0.0, 0.016703, 0.016437, 0.015997, 0.060473, 0.021266, 0.005723, 0.138001, 0.071008, 0.021814, 0.033982, 0.009205, 0.108593, 0.015237, 0.074121, 0.013281, 0.000191, 0.029631, 0.0519, 0.061154, 0.086131, 0.0, 0.049096, 0.082816, 0.072189, 0.052865, 0.0, 0.015066, 0.041518, 0.069102, 0.045476, 0.021399, 0.011514, 0.003963, 0.034423, 0.0, 0.04961, 0.096743, 0.04341, 0.020693, 0.0, 0.0, 0.001971, 0.048771, 0.048558, 0.0, 0.017236, 0.0, 0.04677, 0.0467, 0.03194, 0.0, 0.048829, 0.026097, 0.042147, 0.0, 0.005696, 0.0, 0.049209, 0.063318, 0.011795, 0.036663, 0.0, 0.11124, 0.002566, 0.009413, 0.0, 0.0, 0.0, 0.092952, 0.0, 0.043978, 0.192276, 0.104189, 0.054416, 0.106153, 0.009525, 0.0, 0.012452, 0.004012, 0.061031, 0.0, 0.0, 0.012454, 0.0621, 0.059129, 0.004631, 0.021704, 0.0, 0.016536, 0.05911, 0.041772, 0.030186, 0.029198, 0.0, 0.0, 0.057916, 0.029196, 0.005615, 0.0, 0.005348, 0.058839, 0.044673, 0.000128, 0.0]
					}]
				},
				"size": 30,
				"parallel": true
			}
		`,
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	log.Println(response)
}
